package com.ljx.controller;


import com.ljx.Vo.LoginVo;
import com.ljx.Vo.Result;
import com.ljx.entity.Dept;
import com.ljx.service.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * @author LJX
 * @Description: TODO
 * @Date: 2022/11/17 17:17
 * @Version 1.0
 */
/**
 origins = {"*"}允许那些域来请求,allowedHeaders = {"*"}允许携带那些请求头的请求跨域,methods = {RequestMethod.GET}允许那些请求方式跨域,allowCredentials ="true"是否要求携带凭证
 @CrossOrigin(origins = {"*"},allowedHeaders = {"*"},allowCredentials ="true")
 */
@RestController
@RequestMapping("/dept")
@Api(tags = "对dept表的crud")
public class DeptController {
	@Autowired
	private DeptService deptService;

	@ApiOperation(value = "此注解是对该方法的描述")
	@PostMapping("/login")
	public Result login(@RequestBody LoginVo loginVo){
		return deptService.loginVerify(loginVo);
	}


	@ApiImplicitParams({
			@ApiImplicitParam(name = "currentPage",value = "当前第几页"),
			@ApiImplicitParam(name = "pageSize",value = "一页几条数据")
	})
	@GetMapping("/selectAll")
	public Result select(@RequestParam(defaultValue = "1")int currentPage, @RequestParam(defaultValue = "5")int pageSize){
		System.out.println(currentPage+"-------------------"+pageSize);
		return deptService.findAllDept(currentPage,pageSize);
	}

	@ApiOperation(value = "根据部门id更新部门信息")
	@RequestMapping("/update")
	public Result update(@RequestBody Dept dept){
		System.out.println("-----------------"+dept);
		return deptService.updateDeptById(dept);
	}

	@ApiOperation(value = "插入部门信息")
	@PostMapping("/insert")
	public Result insert(@RequestBody Dept dept){
		return deptService.insertOne(dept);
	}
	@ApiOperation(value = "根据部门id删除一条部门信息")
	@ApiImplicitParam(name = "id",value = "部门编号")
	@RequestMapping("/delete")
	public Result delete(int id){
		return deptService.deleteById(id);
	}

}
